﻿using System;
using System.Collections.Generic;
using System.Threading;
using Hohlios.TMDBWrapper.DotNet.Model;
using NUnit.Framework;

namespace Hohlios.TMDBWrapper.DotNet.Tests
{
    [TestFixture]
    public class BasicFunctionalityTests
    {
        private const string API_KEY = "YOUR_API_KEY_HERE";
        private TMDBWrapper _wrapper;

        [SetUp]
        public void Setup()
        {
            _wrapper = new TMDBWrapper(API_KEY);
        }

        [Test]
        public void TestMovieSearch()
        {
            List<Movie> result = null;
            _wrapper.MovieSearch(a => result = a, "Tron");

            while (result == null) { Thread.Sleep(250); }

            Assert.That(result != null);
            Assert.That(result.Count > 1);
        }

        [Test]
        public void TestMovieSearchWithSpaces()
        {
            List<Movie> result = null;
            _wrapper.MovieSearch(a => result = a, "Tron Legacy");

            while (result == null) { Thread.Sleep(250); }

            Assert.That(result != null);
            Assert.That(result.Count == 1);
            Assert.That(result[0].Name == "TRON: Legacy");
        }

        [Test]
        public void TestMovieSearchWithSpacesAndYear()
        {
            List<Movie> result = null;
            _wrapper.MovieSearch(a => result = a, "Star Trek", "2002");

            while (result == null) { Thread.Sleep(250); }

            Assert.That(result != null);
            Assert.That(result.Count == 1);
            Assert.That(result[0].Name == "Star Trek: Nemesis");
        }

        [Test]
        public void TestMovieGetInfo()
        {
            List<MovieInfo> result = null;
            _wrapper.MovieGetInfo(a => result = a, "20526");

            while (result == null) { Thread.Sleep(250); }

            Assert.That(result != null);
            Assert.That(result.Count == 1);
            Assert.That(result[0].Name == "TRON: Legacy");
        }

        [Test]
        public void TestMovieImdbLookup()
        {
            List<Movie> result = null;
            _wrapper.MovieIMDBLookup(a => result = a, "tt0468569");

            while (result == null) { Thread.Sleep(250); }

            Assert.That(result != null);
            Assert.That(result.Count == 1);
            Assert.That(result[0].Name == "The Dark Knight");
        }

        [Test]
        public void TestMovieBrowse()
        {
            var args = new MovieBrowseOptions{ Query = "Tron", Order = Order.asc};
            List<Movie> result = null;
            _wrapper.MovieBrowse(a => result = a, args);

            while (result == null) { Thread.Sleep(250); }

            Assert.That(result != null);
            Assert.That(result.Count > 1);
        }
    }
}
